
use if inrange(year,2008,2010) using "${data}/Utils/sirenZE_dads_0519", clear
destring siren, replace
merge m:1 siren year using "${data}/Utils/Mere_fille_0420", nogen keep(1 3)
replace siren_gf = siren if mi(siren_gf)
ren siren sirenfille
ren siren_gf siren
gcollapse (sum) nbheur_eng nbheur_tech nbheur_hskill nbheur_tot , by(siren apet)
gen nonfin = (!inrange(real(substr(apet,1,2)),64,68) & substr(apet,1,2) != "70")
gen share_eng = nbheur_eng / nbheur_tot
gen share_hskill = nbheur_hskill / nbheur_tot
gsort siren - nonfin - nbheur_eng - nbheur_tech - share_hskill
bys siren: keep if _n == 1
keep siren apet
compress
save "${data}/Utils/SirenApet_maineng_consolidate", replace


use if inrange(year,2008,2010) using "${data}/Utils/sirenZE_dads_0519", clear
destring siren, replace
gcollapse (sum) nbheur_eng nbheur_tech nbheur_hskill nbheur_tot , by(siren apet)
gen nonfin = (!inrange(real(substr(apet,1,2)),64,68) & substr(apet,1,2) != "70")
gen share_eng = nbheur_eng / nbheur_tot
gen share_hskill = nbheur_hskill / nbheur_tot
gsort siren - nonfin - nbheur_eng - nbheur_tech - share_hskill
bys siren: keep if _n == 1
keep siren apet
compress
save "${data}/Utils/SirenApet_maineng_noconsolidate", replace
